package com.andy.module.widget

import android.graphics.Rect
import android.view.View
import androidx.recyclerview.widget.RecyclerView

/**
 * @creator:LuoFan
 * @date:2022/6/7
 * @description:
 */
class GridDecoration : RecyclerView.ItemDecoration() {

    var verticalSpace = 0
    var horizontalSpace = 0
    var columnCount = 3

    override fun getItemOffsets(outRect: Rect, view: View, parent: RecyclerView, state: RecyclerView.State) {
        val position = parent.getChildLayoutPosition(view)
        outRect.left = position * horizontalSpace / columnCount
        //右侧为(总条目数-当前条目数)/总条目数*divider宽度
        outRect.right = (columnCount - position - 1) * horizontalSpace / columnCount
        outRect.bottom = verticalSpace
    }
}